/*
 * @lc app=leetcode.cn id=409 lang=cpp
 *
 * [409] 最长回文串
 */

// @lc code=start

#define INDEX(c)(c>='a'?c-'a':c-'A'+26)

class Solution
{

public:

    int longestPalindrome(string s)
    {
        int cnt[26 * 2] = {0};
        for (char c : s)
        {
            cnt[INDEX(c)]++;
        }
        int ans = 0;
        bool flag = false;
        for (int i = 0; i < 26 * 2; i++)
        {
            ans += cnt[i] / 2;
            if (cnt[i] & 1)
            {
                flag = true;
            }
        }
        return ans * 2 + flag;
    }
};
// @lc code=end
